<?php

namespace App\Http\Queries;

use App\Models\Admin\AdminPower;
use Spatie\QueryBuilder\AllowedFilter;
use Illuminate\Database\Eloquent\Builder;

class AdminPowerQuery extends BaseQuery
{

    public function __construct()
    {
        // 字符搜索
        $this->strSearch = ['power', 'power_name'];
        // 等值搜索
        $this->eqSearch = ['is_check', 'controller_name', 'module_name'];
        // 时间搜索
        $this->timeSearch = ['start_time', 'end_time'];
        $this->timeAttribute = 'created_at';
        //预加载约束
        parent::__construct(AdminPower::query());

        if ($this->request->has('role_id')){
            $this->whereHas('roles', function (Builder $query) {
                $query->where('role_id', '=', $this->request->input('role_id'));
            });
        }

        $this->toOrderBy();
    }
}
